package com.hly.dao;

import com.hly.model.Orders;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @program: hly_emall_ssm
 * Author HLY
 * @desc
 * @create: 2020-10-12 10:52
 **/
public interface IOrdersDao {

    @Insert("insert into orders (total,amount,status,paytype,name,phone,address,systime,user_id) " +
            "values (#{total},#{amount},#{status},#{paytype},#{name},#{phone},#{address},now(),#{userId})")
    @SelectKey(keyProperty = "id" , statement = "SELECT LAST_INSERT_ID()", before = false, resultType = Integer.class)
    public Integer insertOrder(Orders orders);

    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(id = true , property = "id" , column = "id"),
            @Result(property = "total",column = "total"),
            @Result(property = "amount",column = "amount"),
            @Result(property = "status",column = "status"),
            @Result(property = "paytype",column = "paytype"),
            @Result(property = "name",column = "name"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "address",column = "address"),
            @Result(property = "systime",column = "systime"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "itemList" , column = "id" ,
            many = @Many(select = "com.hly.dao.IitemsDao.selectByOrderId" , fetchType = FetchType.LAZY)
            )
    })
    public Orders selectById(@Param("id") Integer orderId);
}
